package com.kmzx.one.project.service.impl;

import com.kmzx.one.project.entity.Charges;
import com.kmzx.one.project.entity.FreightTariff;
import com.kmzx.one.project.mapper.ChargesMapper;
import com.kmzx.one.project.others.dto.EntryFeeInfo;
import com.kmzx.one.project.service.FeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;

@Service
public class FeeServiceImpl implements FeeService {

    @Autowired
    ChargesMapper chargesMapper;

    @Override
    public EntryFeeInfo findEntryFeeInfo(Integer tradeType, String code) {
        EntryFeeInfo info = new EntryFeeInfo();
        info.setTradeType(tradeType);
        info.setExFee(BigDecimal.ZERO)
                .setGateFeeRate(BigDecimal.ZERO)
        .setExUse(1).setGateUse(1).setExGateUse(1);
        // 韩国满_ _金额减邮费,税费
        List<String> codes = Arrays.asList("540000","650000","710000","810000","820000","900000");
        if(code!=null && !codes.contains(code)){
            code = "E";
        }
        if (code == null || "".equals(code)) {
            code = "E";
        }
        if (tradeType == 1) {
            FreightTariff gateFee = chargesMapper.selectGateFee();
            if (gateFee != null) {
                info.setExGateFullMoney(gateFee.getFullMoney())
                        .setExGateAppendMoney(gateFee.getPayMoney())
                        .setExGateUse(gateFee.getToUse());
            }
        } else if (tradeType == 2) {

            Charges charges = chargesMapper.selectChargeFee(tradeType, code);
            if (charges != null) {
                info.setExFee(charges.getChargesPrice())
                        .setExUse(charges.getToUse())
                        .setGateFeeRate(charges.getChargesNumber())
                        .setGateUse(charges.getToUse2());
            }
        } else if (tradeType == 0) {
            Charges charges = chargesMapper.selectChargeFee(tradeType, code);
            if (charges != null) {
                info.setExFee(charges.getChargesPrice())
                        .setGateFeeRate(charges.getChargesNumber())
                        .setExUse(charges.getToUse())
                        .setGateUse(charges.getToUse2());
            }
        }

        return info;
    }
}
